package lance.honeydew.dao;

import java.util.List;

import lance.honeydew.bean.CategoryBig;
import lance.honeydew.bean.PaymentMethod;
import lance.honeydew.bean.PublishMessage;
import lance.honeydew.bean.UserMember;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;

public class PaymentMethodDAO extends RootDAO {
	
	private static final Logger logger = Logger.getLogger(PaymentMethodDAO.class);
	
	/**
	 * findPaymentMethodBySeqId
	 * @param seqId
	 * @return
	 */
	public PaymentMethod findPaymentMethodBySeqId(Long seqId) {
		
		PaymentMethod result = null;
		
		try {
			
			DetachedCriteria criteria = DetachedCriteria.forClass(PaymentMethod.class);
			criteria.add(Restrictions.eq(PaymentMethod.PROP_SEQID, seqId));
			
			criteria.setProjection(Projections.projectionList()
					.add(Projections.property(PaymentMethod.PROP_SEQID), "_seqid")
					.add(Projections.property(PaymentMethod.PROP_PAYMENTNAME), "_paymentname")
					);
			criteria.setResultTransformer(Transformers.aliasToBean(PaymentMethod.class));
			
			result = (PaymentMethod) this.getHibernateTemplate().
					findByCriteria(criteria).get(0);
			
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return result;
	}
	
	/**
	 * queryPaymentMethodByQb
	 * @param qb
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public List<PaymentMethod> queryPaymentMethodByQb(PaymentMethod qb, int pageNum, int pageSize) {
		
		DetachedCriteria criteria = DetachedCriteria.forClass(PaymentMethod.class);
		List<PaymentMethod> list = null;
		
		try {
			
			if (StringUtils.isNotEmpty(qb.getPaymentname())) {
				criteria.add(Restrictions.like(PaymentMethod.PROP_PAYMENTNAME, qb.getPaymentname(), MatchMode.ANYWHERE));
			}
			
			list = (List<PaymentMethod>) this.getHibernateTemplate().
					findByCriteria(criteria);
			
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return list;
	}
	
	/**
	 * findAllPaymentMethodList
	 * @return
	 */
	public List<PaymentMethod> findAllPaymentMethodList() {
		
		DetachedCriteria criteria = DetachedCriteria.forClass(PaymentMethod.class);
		List<PaymentMethod> list = null;
		
		try {
			
			criteria.setProjection(Projections.projectionList()
					.add(Projections.property(PaymentMethod.PROP_SEQID), "_seqid")
					.add(Projections.property(PaymentMethod.PROP_PAYMENTNAME), "_paymentname"));
			criteria.setResultTransformer(Transformers.aliasToBean(PaymentMethod.class));
			
			list = (List<PaymentMethod> ) this.getHibernateTemplate().
					findByCriteria(criteria);
			
		} catch(Exception e) {
			e.printStackTrace();
			logger.debug(e);
		}
		
		return list;
	}
}